<template>
	<view :style="theme">
		<!-- #ifdef MP-WEIXIN -->
		<u-navbar :placeholder="false" :bgColor="bgColor">
			<view slot="left" class="nav_title" @click="navBack">
				<u-icon name="arrow-left" color="#fff" /><text style="z-index: 10;color: #fff">限时秒杀</text>
			</view>
		</u-navbar>
		<!-- #endif -->
		<image :src="imgHost + '/miaosha_bg@2x.png'" class="banner" mode="widthFix"></image>
		<view class="tabList flex">
			<view v-for="(item, index) in tabList" :key="index" :class="tabIndex===index?'on':''" @click="clickTabs(index)">
				{{item}}
			</view>
		</view>
		<view class="cardCont btCont">
			<image :src="imgHost + '/title_miaosha_b@2x.png'" mode="widthFix" class="title"></image>
			<view v-for="(item, index) in list" :key="index" class="box_item mb2" @click="jumpBtn(item)">
				<image :src="imgHost + '/ic_miaosha@2x.png'" class="ms"></image>
				<view class="head flex">
					<view class="zsd f26">
						{{item.status == '0'?'距秒杀开始：' :item.status == '1'? '距秒杀结束：':'已结束'}}
					</view>
					<u-count-down v-if="item.status!='2'" :time="item.time" format="DD:HH:mm:ss" autoStart millisecond
						@change="onChange($event, index)">
						<view class="time">
							<text v-if="item.timeData.days && item.timeData.days > 0" class="time__item">{{ item.timeData.days }}</text>
							<text v-if="item.timeData.days && item.timeData.days > 0" class="jg">天</text>
							<text
								class="time__item">{{ item.timeData.hours>=10?item.timeData.hours:'0'+item.timeData.hours}}</text>
							<text class="jg">:</text>
							<text class="time__item">{{ item.timeData.minutes }}</text>
							<text class="jg">:</text>
							<text class="time__item">{{ item.timeData.seconds }}</text>
						</view>
					</u-count-down>
				</view>
				<view class="cont flex">
					<image :src="item.businessImg?item.businessImg:imgHost+'/default_list.jpg'" class="left"></image>
					<view class="right">
						<view class="f30 c2 limit-1-line">
							{{item.businessName || ''}}
						</view>
						<view class="f22 c9 mt10">
							{{item.businessInfo}}
						</view>
						<view class="zsd flex mt10 flex_between">
							<view class="f22">
								<text>秒杀价</text>
								<text>¥</text>
								<text>{{item.discountPrice}}</text>
								<text>¥{{item.businessOriginPrice}}</text>
							</view>
							<view v-if="item.status != '0'" class="payBtn">
								马上抢
							</view>
							<view v-if="item.status == '0'" class="payBtn hui">
								即将开抢
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore v-if="end && list.length >= 10" :status="status" line />
			<view v-if="list.length === 0" class="no-order">
				<image :src="imgHost+'/default_nodata.png'"></image>
				<view>暂无数据</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgColor: 'rgba(254, 57, 59, 0)',
				tabList: ['全部','进行中','未开始'],
				tabIndex: 0,
				status: 'nomore',
				page: 1,
				rows: 10,
				noClick: true,
				end: false,
				list: [],
				firstQueryTime: '',
			}
		},
		onLoad(ops) {
			this.firstQueryTime = this.$app.firstQueryTime()
			this.getList()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			jumpBtn(e) {
				if(e.businessType == '04') {
					this.jump('/pages/setmeal/detail?id=',e.businessId)
				} else if(e.businessType == '07') {
					this.jump('/pages/curriculum/detail?id=', e.businessId)
				} else if(e.businessType == '19') {
					this.jump('/subPackages/special/details?id=',e.businessId)
				}
			},
			navBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			onChange(e, s) {
				this.list[s].timeData = e
			},
			clickTabs(index) {
				this.tabIndex = index
				this.firstQueryTime = this.$app.firstQueryTime()
				this.list = [];
				this.page = 1;
				this.end = false;
				this.getList()
			},
			getList() {
				this.$app.ajax({
					api: this.$api.secKillList(),
					data: {
						pagination: {
							page: this.page,
							firstQueryTime: this.firstQueryTime,
							rows: 10
						},
						param: {
							type: '0',
							status: this.tabIndex=='0'?'': this.tabIndex=='1'?'1':'0'
						}
					}
				}).then((res) => {
					if (res.errorCode === '000000') {
						if (!res.recordList || res.recordList.length < this.rows) {
							this.end = true
						}
						if (res.recordList) {
							let list = res.recordList || []
							list.forEach((s) => {
								if (s.status == 0) {
									s.time = s.duration * 1000
								} else if (s.status == 1) {
									s.time = s.duration * 1000
								} else {
									s.time = 0
								}
								s.timeData = {}
							})
							this.list = this.list.concat(list)
						}
					}
				}).catch(() => {})
			},
			reachBottom() {
				if (!this.end) {
					this.page += 1;
					this.getList();
				}
			},
			// 触底加载更多数据
			onReachBottom(e) {
				this.reachBottom()
			}
		},
		onPageScroll(res) {
			let topOpacity = res.scrollTop / 100 - .4
			if (res.scrollTop < 40) {
				topOpacity = 0
			} else if (topOpacity >= 1) {
				topOpacity = 1
			}
			this.bgColor = `rgba(254, 57, 59,${topOpacity})`
		}

	}
</script>
<style>
	page {
		background-color: rgba(254, 57, 59, 1);
	}
</style>
<style lang="scss" scoped>
	.zsd {
		color: #FE2C2E;
	}
	.banner {
		width: 100%;
		vertical-align: top;
	}
	.title {
		display: block;
		width: 210rpx;
		height: 50rpx;
		margin: auto;
		padding: 24rpx 0;
	}
	.tabList {
		width: 690rpx;
		margin: 30rpx auto;
		background-color: rgb(254,78,80);
		box-sizing: border-box;
		border-radius: 32rpx;
		view {
			width: 230rpx;
			height: 64rpx;
			line-height: 64rpx;
			font-size: 28rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			box-sizing: border-box;
			&.on {
				background: #FFFFFF;
				border-radius: 32rpx;
				font-weight: Medium;
				color: #FE2C2E;
			}
		}
	}
	.btCont {
		width: 710rpx;
		background: #F7F7F7;
		border-radius: 16rpx;
		box-sizing: border-box;
		padding: 0 10rpx 20rpx;
		.btImg {
			height: 102rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			image {
				width: 210rpx;
				height: 50rpx;
			}
		}
		.box_item {
			box-sizing: border-box;
			background: linear-gradient(360deg, #FFFFFF 0%, #FFD7DB 100%);
			border-radius: 8rpx;
			position: relative;
			.ms {
				position: absolute;
				right: 34rpx;
				z-index: 2;
				width: 88rpx;
				height: 88rpx;
				top: 0rpx;
			}
	
			.head {
				height: 88rpx;
				padding: 0 20rpx;
				box-sizing: border-box;
	
				.zsd {
					font-weight: Medium;
				}
	
				.time {
					font-size: 26rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FE2C2E;
	
					text {
						display: inline-block;
	
						&.jg {
							margin: 0 8rpx;
						}
	
						&.time__item {
							width: 44rpx;
							height: 44rpx;
							text-align: center;
							line-height: 44rpx;
							background: rgba(34, 34, 34, 1);
							border-radius: 16rpx;
							font-size: 26rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: Medium;
							color: #FFFFFF;
						}
					}
				}
	
			}
	
			.cont {
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 8rpx 8rpx;
				padding: 16rpx;
				box-sizing: border-box;
	
				.left {
					width: 212rpx;
					height: 120rpx;
					border-radius: 8rpx;
					margin-right: 16rpx;
					flex: none;
				}
	
				.right {
					flex: 1;
	
					.zsd {
						height: 52rpx;
	
						.f22 {
							text {
								display: inline-block;
	
								&:nth-of-type(2) {
									margin-left: 4rpx;
								}
	
								&:nth-of-type(3) {
									font-size: 32rpx;
									font-weight: bolder;
								}
	
								&:nth-of-type(4) {
									margin-left: 8rpx;
									text-decoration: line-through;
									color: #999999;
								}
							}
						}
					}
	
					.payBtn {
						width: 110rpx;
						height: 52rpx;
						text-align: center;
						line-height: 52rpx;
						background: linear-gradient(270deg, #FE2C2E 0%, #FF6A1F 100%);
						box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(254, 44, 46, 0.24);
						border-radius: 26rpx;
						font-size: 26rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: Medium;
						color: #FFFFFF;
	
						&.hui {
							width: 136rpx;
							background: linear-gradient(270deg, #FE2C2E 0%, #FF7C30 100%);
							box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(254,44,46,0.24);
							opacity: 0.6;
						}
					}
				}
			}
		}
	}
</style>